package com.itheima.manager;


import cn.hutool.core.collection.CollUtil;
import com.itheima.common.ResultData;
import com.itheima.domain.UmsResourceCategory;
import com.itheima.service.UmsResourceCategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 资源分类表 前端控制器
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */

@Component
public class UmsResourceCategoryManager {
    @DubboReference
    private UmsResourceCategoryService umsResourceCategoryService;


    // 查询后台所有资源分类
    public ResultData listAll() {
        List<UmsResourceCategory> umsResourceCategories = umsResourceCategoryService.getAll();
        /*if (CollUtil.isEmpty(umsResourceCategories)) {
            return new ArrayList<>();
        }*/
        return ResultData.ok(umsResourceCategories,"");
    }

    // 添加后台资源分类
    public ResultData create(UmsResourceCategory category) {
        umsResourceCategoryService.create(category);
        return ResultData.ok("","添加成功");
    }

    // 根据ID删除后台资源
    public ResultData deleteCategoryById(Integer id) {
        umsResourceCategoryService.deleteCategoryById(id);
        return ResultData.ok("","删除成功");
    }


    // 修改后台资源分类
    public ResultData updateCategoryById(Integer id, UmsResourceCategory resourceCategory) {
        umsResourceCategoryService.updateCategoryById(id,resourceCategory);
        return ResultData.ok("","修改成功");
    }
}

